package com.king.designpatterns.行为模式.中介者模式;

import java.util.ArrayList;
import java.util.List;

/**
 * 具体接口实现类 - 婚姻中介所实现类
 *
 * @author king
 * @date 2021-06-10 18:00
 */
public class MarriageAgencyImpl implements MarriageAgency{
    /**
     * 男会员
     */
    List<Man> man = new ArrayList<>();
    /**
     * 女会员
     */
    List<Woman> woman = new ArrayList<>();

    @Override
    public void pair(Person person) {
        if (person.sex == Sex.MAN){
            for (Woman w : woman){
                if (w.age == person.requestAge){
                    System.out.println(person.name + "和" + w.name + "配对成功");
                    return;
                }
            }
        }else if(person.sex == Sex.WOMAN){
            for(Man m : man){
                if (m.age == person.requestAge){
                    System.out.println(person.name + "和" + m.name + "配对成功");
                    return;
                }
            }
        }
        System.out.println("没有为" + person.name + "找到合适的对象");
    }

    @Override
    public void register(Person person) {
        if (person.sex == Sex.MAN){
            man.add((Man)person);
        }else if(person.sex == Sex.WOMAN){
            woman.add((Woman)person);
        }
    }
}
